/* 后端写接口 */
/* 
Express 是基于 Node.js 平台，快速、开放、极简的 Web 开发框架
使用 Express，我们可以方便、快速的创建 Web 网站的服务器或 API 接口的服务器。 
*/
/* import { Router } from 'express';  应该是没有es模块 */
var express = require('express');
/* var express = require('router'); */
/* router是创建一个实例 */
/* var router = Router(); 不支持的es模块*/
var router = express.Router();//路由实例

var connection=require("../db/sql.js");/* 接收 */

//在userSql.js里面 抛出的exports = module.exports = User; 在这里请求
var user=require("../db/userSql.js");//引入user

var QcloudSms = require("qcloudsms_js");//引入包 短信验证码
let jwt = require('jsonwebtoken'); //解token

/*
app.get(path,callback) callback只能传入回调函数，不能传入路由对象。
app.use(path,callback) callback传入回调函数和路由对象皆可。 
都是应用级的中间件
*/

//引入支付宝配置文件
const alipaySdk = require('../db/alipay.js');
const AlipayFormData = require('alipay-sdk/lib/form').default;


//引入axiso
const axios = require('axios');

/* function getTimeToken(exp){
	//将毫秒转换为时间
	let getTime=parseInt(new Date().getTime()/1000);
	if (getTime-exp > 60000){
			return true;
		}else{
			return false;
		};
}; */


function getTimeToken( exp ){
    //将毫秒转换为时间
    let getTime = parseInt(  new Date().getTime() / 1000 );
    
    if(  getTime - exp  >  6000 ){
        return true;
    }
    
} 

/* GET home page. */   /* 用get请求来做 */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
  next();
});


//支付状态
router.post('/api/successPayment',function(req,res,next){
	/* 	res.send({
		data:{a:1}
	}) 		*/
	//拿到token干
    //token
    let token = req.headers.token;
    let tokenObj = jwt.decode(token);
	/* 	res.send({
		data:{a:1}
	}) 		*/
	//通过这个一个一个的测，不断console.log()找出哪个错了
    //订单号  接口文档
	//out_trade_no: this.$route.query.out_trade_no,
	//trade_no: this.$route.query.trade_no,
    let out_trade_no = req.body.out_trade_no;//自己生成的订单号
    let trade_no = req.body.trade_no;//支付宝订单号
    //支付宝配置  新建一个对象
    const formData = new AlipayFormData();
    // 调用 setMethod 并传入 get，会返回可以跳转到支付页面的 url
    formData.setMethod('get');
    //支付时信息
    formData.addField('bizContent', {
      out_trade_no,
      trade_no
    });
    //返回promise
	//Promise 对象用于表示一个异步操作的最终完成 (或失败)及其结果值。
    const result = alipaySdk.exec(
      'alipay.trade.query',
	  //'alipay.trade.page.pay',=》这个不行
      {},
      { formData: formData },
    );
	//上面 ↑ 返回 promise
    //后端请求支付宝
    result.then(resData=>{
        axios({
            method:'GET',
            url:resData
        }).then(data=>{
			//console.log(data);=》打印，确定各种变量
            //let responseCode 数据主体
			//第一个data是.then data=》
			let responseCode = data.data.alipay_trade_query_response;
			//状态值1000是ok的 返回成功
            if(  responseCode.code == '10000' ){
				//下面通过switch来判断支付状态
				//trade_status  支付状态
                switch(  responseCode.trade_status  ){
                    case 'WAIT_BUYER_PAY':
                        res.send({
                            data:{
                                code:0,
                                data:{
                                    msg:'支付宝有交易记录，没付款'
                                }
                            }
                        })
                    break;
                    
                    case 'TRADE_CLOSED':
                        res.send({
                            data:{
                                code:1,
                                data:{
                                    msg:'交易关闭'
                                }
                            }
                        })
                    break;
                    
                    case 'TRADE_FINISHED':
                        connection.query(`select * from user where tel = ${tokenObj.tel}`,function(error,results){
                            //用户id
                            let uId = results[0].id;
                            connection.query(`select * from store_order where uId = ${uId} and order_id = ${out_trade_no}`,function(err,result){
                                let id = result[0].id;
                                //订单的状态修改掉2==》3
                                connection.query(`update store_order set order_status = replace(order_status,'2','3') where id = ${id}`,function(){
                                    res.send({
                                        data:{
                                            code:2,
                                            data:{
                                                msg:'交易完成'
                                            }
                                        }
                                    })
                                })
                            })
                        })
                    break;
                    
                    case 'TRADE_SUCCESS':
                        connection.query(`select * from user where tel = ${tokenObj.tel}`,function(error,results){
                            //用户id
                            let uId = results[0].id;
                            connection.query(`select * from store_order where uId = ${uId} and order_id = ${out_trade_no}`,function(err,result){
                                let id = result[0].id;
                                //订单的状态修改掉2==》3
                                connection.query(`update store_order set order_status = replace(order_status,'2','3') where id = ${id}`,function(){
                                    res.send({
                                        data:{
                                            code:2,
                                            data:{
                                                msg:'交易完成'
                                            }
                                        }
                                    })
                                })
                            })
                        })
                    break;
                }
            }else if( responseCode.code == '40004' ){
                res.send({
                    data:{
                        code:4,
                        msg:'交易不存在'
                    }
                })
            }//要捕获一下
        }).catch( err=>{
            res.send({
                data:{
                    code:500,
                    msg:'交易失败',
                    err  //返回 err 对象
                }
            })
        })
    })
})

//发起支付
router.post('/api/payment',function(req,res,next){
    //订单号
    let orderId = req.body.orderId;
    //商品总价
    let price = req.body.price;
    //购买商品的名称
    let name = req.body.name;
	//获得前端的数据后
    //开始对接支付宝API
    const formData = new AlipayFormData();
    // 调用 setMethod 并传入 get，会返回可以跳转到支付页面的 url
    formData.setMethod('get');
    //支付时信息 =>下面开始传价格进去
    formData.addField('bizContent', {
      outTradeNo: orderId,//订单号
      productCode: 'FAST_INSTANT_TRADE_PAY',//写死的
      totalAmount: price,//价格  传价格进去
      subject: name,//商品名称
	  body:'描述:游戏商城结算',//商品详情
    });
    //支付成功或者失败跳转的链接
    formData.addField('returnUrl', 'http://localhost:8080/payment');
    //返回promise
    const result = alipaySdk.exec(
      'alipay.trade.page.pay',
      {},
      { formData: formData },
    );
    //对接支付宝成功，支付宝方返回的数据
    result.then(resp=>{
        res.send({
            data:{
                code:200,
                success:true,
                msg:'支付中',
                paymentUrl : resp //返回的是链接
            }
        })
    })
})
/* 测试支付一定要用无痕浏览 沙箱的设置 */
//修改订单状态
router.post('/api/submitOrder',function(req,res,next){
    //token
    let token = req.headers.token;
    let tokenObj = jwt.decode(token);
    //订单号  
    let orderId = req.body.orderId;
    //购物车选中的商品id  传过来的
    let shopArr = req.body.shopArr;
    //查询用户  传过来的
    connection.query(`select * from user where tel = ${tokenObj.tel}`,function(error,results){
        //用户id
        let uId = results[0].id;
        connection.query(`select * from store_order where uId = ${uId} and order_id = ${orderId}`,function(err,result){
            //订单的数据库id
            let id = result[0].id;
            //修改订单状态 1==>2  未支付=>待支付
            connection.query(`update store_order set order_status = replace(order_status,'1','2') where id = ${id}`,function(e,r){
                //购物车数据删除 重点 
                shopArr.forEach(v=>{ //了解这个 V 
                    connection.query(`delete from goods_cart where id = ${v}`,function(){
					/*res.send({
                            data:{
                                code:200,
                                success:true
                            }
                        }) 
						*/
						//不能放这里，否者会删除多少个商品，发送多少次
                    })
				})
				res.send({
					data:{
						code:200,
						success:true
					}
				}) 
            })
        })
    })
    
})

//查询订单
router.post('/api/selectOrder',function(req,res,next){
    //接收前端给后端的订单号
    let orderId = req.body.orderId;
    connection.query(`select * from store_order where order_id='${orderId}'`,function(err,result){
         res.send({
            data:{
                 success:true,
                 code:200,
                 data:result
            }
         })
    })
})

//生成一个订单
router.post('/api/addOrder',function(req,res,next){
    //token
	let token = req.headers.token;
	let tokenObj = jwt.decode(token);
	//前端给后端的数据
	let goodsArr=req.body.arr;
	//生成订单号 order_id 规则：时间戳 + 6位的随机数
	function setTimeDateFmt(s){
		return s < 10 ? '0' + s : s///补零函数
		/*
		returns < 10 ? '0' + s : s///补零函数
		return s < 10 ? '0' + s : s///补零函数
		xhr.js?1a5c:210 POST http://localhost:8080/api/addOrder 500 (Internal Server Error) 
		就是这里导致返回500
		*/
		
	}
/* 	function randomNumber(){
		const now= new Date();
		let year =setTimeDateFmt(now.getFullYear()+1);
		let month = setTimeDateFmt(now.getMonth()+1);
		let day = setTimeDateFmt(now.getDate());
		let hour =setTimeDateFmt(now.getHours());

	} */

	function randomNumber(){
        const now = new Date();
        let month = now.getMonth() + 1;
        let day = now.getDate();
        let hour = now.getHours();
        let minutes = now.getMinutes();
        let seconds = now.getSeconds();
		// 他下面不用let 的差别  了解 下面也是let，不是说let 不能再被赋值吗？？
        month = setTimeDateFmt(month);
        day = setTimeDateFmt(day);
        hour = setTimeDateFmt(hour);
        minutes = setTimeDateFmt(minutes);
        seconds = setTimeDateFmt(seconds);
		//字符串拼接  伪随机数
        let orderCode = now.getFullYear().toString() + month.toString() + day + hour + minutes + seconds + (Math.round(Math.random() * 1000000 )).toString();
		//字符串拼接
        return orderCode;
    }
	//console.log(randomNumber());
	//先给前端返回一个数据防止报错
	/* 	res.send({   //这里是前期调试
		data:{a:1}//前端 这里的a不用定义
	}) */
	/*
    未支付：1
    待支付：2
    支付成功：3
    支付失败：4 | 0
    */
   //新建列表，然后遍历
    //商品列表名称
	let goodsName = [];
	//订单商品总金额
	let goodsPrice = 0;
	//订单商品总数量
	let goodsNum = 0;
	//将goodsArr进行遍历 goodsArr（前端给后端的数据）放进表里
	//let goodsArr=req.body.arr;这里
	//设定这个变量是到最后查询返回单个就他的订单（指定订单）
	//订单号
	let orderId=randomNumber();

	goodsArr.forEach(v=>{
        goodsName.push( v.goods_name );
        goodsPrice += v.goods_price * v.goods_num;
        goodsNum += parseInt(v.goods_num);//数据库里面goodsNum是int类型  //不parseInt就string类型了
    })
	//查询当前用户
	//!!!应该在外围打印console.log
    connection.query(`select * from user where tel = ${tokenObj.tel}`,function(error,results){
		//用户ID
		let uId = results[0].id;
		//插入数据  //由于时间随机数太大了，所以vchar要设置得大一点，否者可能出现不能插入!是有可能出现这种情况的
		connection.query(`insert into store_order (order_id,goods_name,goods_price,goods_num,order_status,uId) values ('${ orderId }','${goodsName}','${goodsPrice}','${goodsNum}','1',${uId})`,function(/* 这里可以不写 */){
			//存储完再查状态  返回前端返回状态
			//这里返回可能好多个数据，需要针对做清除
			connection.query(`select * from store_order where uId = ${uId} and order_id='${orderId}'`,function(err,result){
				res.send({
					data:{
						success:true,
						code:200,
						/* data:result[0].order_id, */
						data:result,
					}
				})
			})
	   })
	})
		
})

//删除收货地址
router.post('/api/deleteAddress',function(req,res,next){
    let id = req.body.id;//取id
    connection.query(`delete from address where id = ${id}`,function(error,results){
		try {
			res.send({
				data:{
					code:200,
					success:true,
					msg:'删除成功'
				}
			})
		} catch (error) {
			throw error;
		}

    })
})
//修改收货地址
router.post('/api/updateAddress',function(req,res,next){
    //token
    let token = req.headers.token;
    let tokenObj = jwt.decode(token);
    //拿到前端给后端传入的数据
    let body = req.body;
    let [id,name,tel,province,city,county,addressDetail,isDefault,areaCode] = [
        body.id,//这个id是该条数据的ID
        body.name,
        body.tel,
        body.province,
        body.city,
        body.county,
        body.addressDetail,
        body.isDefault,
        body.areaCode
    ];
    //查询用户
	/*     //  原先的查询用户
    connection.query(`select * from user where tel = ${tokenObj.tel}`,function(error,results){
        //用户id
        let uId = results[0].id;
        //增加一条收货地址
        
        if(  isDefault != 1 ){
            connection.query(`insert into address (uId,name,tel,province,city,county,addressDetail,isDefault) values (${uId},"${name}","${tel}","${province}","${city}","${county}","${addressDetail}","${isDefault}")`,function(err,result){
                res.send({
                    data:{
                        code:200,
                        success:true,
                        msg:'收货地址添加成功'
                    }
                })
            })
        }else{
            
            connection.query(`select * from address where uId = ${uId} and isDefault = ${isDefault}`,function(err,result){
                let addressId = result[0].id;
                connection.query(`update address set isDefault = replace(isDefault,'1','0') where id = ${addressId}`,function(){
                    connection.query(`insert into address (uId,name,tel,province,city,county,addressDetail,isDefault) values (${uId},"${name}","${tel}","${province}","${city}","${county}","${addressDetail}","${isDefault}")`,function(e,r){
                        res.send({
                            data:{
                                code:200,
                                success:true,
                                msg:'收货地址添加成功'
                            }
                        })
                    })
                })
            })
            
        }
    }) */
    connection.query(`select * from user where tel = ${tokenObj.tel}`,function(error,results){
        //用户id
        let uId = results[0].id;
        //对应查询到0 或者 1 有没有默认收货地址
        connection.query(`select * from address where uId = ${uId} and isDefault = ${isDefault}`,function(err,result){
            if( result.length > 0 ){//这个意思是查询得到
                let addressId = result[0].id;
                connection.query(`update address isDefault = replace(isDefault,'1','0') where id = ${addressId}`,function(e,r){//这个不懂
                    let updateSql = `update address set uId = ? , name = ? , tel = ? , province = ? , city = ? ,county = ? , addressDetail = ? , isDefault = ? , areaCode = ? where id = ${id}`;
					////这个id是该条数据的ID，忘记加了会导致全部数据都改了
					//问号是下面赋值
                    connection.query(updateSql,[uId,name,tel,province,city,county,addressDetail,isDefault,areaCode],function(errors,datas){
                        res.send({
                            data:{
                                code:200,
                                success:true,
                                msg:'修改成功'
                            }
                        })
                    })
                })
            }else{
                let updateSql = `update address set uId = ? , name = ? , tel = ? , province = ? , city = ? ,county = ? , addressDetail = ? , isDefault = ? , areaCode = ? where id = ${id}`;
                connection.query(updateSql,[uId,name,tel,province,city,county,addressDetail,isDefault,areaCode],function(errors,datas){
                    res.send({
                        data:{
                            code:200,
                            success:true,
                            msg:'修改成功'
                        }
                    })
                })
            }
        })
    })
})
//查询收货地址
router.post('/api/selectAddress',function(req,res,next){
    //token   了解token是怎么获得的
    let token = req.headers.token;//token: true,
    let tokenObj = jwt.decode(token);//
    
    //查询用户
    connection.query(`select * from user where tel = ${tokenObj.tel}`,function(error,results){
        //用户id
        let uId = results[0].id;
        connection.query(`select * from address where uId = ${uId}`,function(err,result){
            res.send({
                data:{
                    code:200,
                    success:true,
                    msg:'查询成功',
                    data:result
                }
            })
        })
    })
})
//新增收货地址
router.post('/api/addAddress',function(req,res,next){
    //token
    let token = req.headers.token;
    let tokenObj = jwt.decode(token);
    //拿到前端给后端传入的数据
    let body = req.body;
    let [name,tel,province,city,county,addressDetail,isDefault,areaCode] = [
        body.name,
        body.tel,
        body.province,
        body.city,
        body.county,
        body.addressDetail,
        body.isDefault,
        body.areaCode
    ];
    
    //查询用户
    connection.query(`select * from user where tel = ${tokenObj.tel}`,function(error,results){
        //用户id
        let uId = results[0].id;
        //增加一条收货地址
        if(  isDefault != 1 ){
            connection.query(`insert into address (uId,name,tel,province,city,county,addressDetail,isDefault,areaCode) values (${uId},"${name}","${tel}","${province}","${city}","${county}","${addressDetail}","${isDefault}","${areaCode}")`,function(err,result){
                res.send({
                    data:{
                        code:200,
                        success:true,
                        msg:'收货地址添加成功'
                    }
                })
            })
        }else{
            
            connection.query(`select * from address where uId = ${uId} and isDefault = ${isDefault}`,function(err,result){
                if( result.length > 0 ){
                    let addressId = result[0].id;
                    connection.query(`update address set isDefault = replace(isDefault,'1','0') where id = ${addressId}`,function(){
                        connection.query(`insert into address (uId,name,tel,province,city,county,addressDetail,isDefault,areaCode) values (${uId},"${name}","${tel}","${province}","${city}","${county}","${addressDetail}","${isDefault}","${areaCode}")`,function(e,r){
                            res.send({
                                data:{
                                    code:200,
                                    success:true,
                                    msg:'收货地址添加成功'
                                }
                            })
                        })
                    })
                }else{
                    connection.query(`insert into address (uId,name,tel,province,city,county,addressDetail,isDefault,areaCode) values (${uId},"${name}","${tel}","${province}","${city}","${county}","${addressDetail}","${isDefault}","${areaCode}")`,function(err,result){
                        res.send({
                            data:{
                                code:200,
                                success:true,
                                msg:'收货地址添加成功'
                            }
                        })
                    })
                }
            })
            
        }
    })
})
//修改购物车数量
router.post('/api/updateNum',function(req,res,next){
    
    let id = req.body.id;
    let changeNum = req.body.num;
    
    connection.query(`select * from goods_cart where id = ${id}`,function(error,results){
        //原来的数量
        let num = results[0].goods_num;
        connection.query(`update goods_cart set goods_num = replace(goods_num,${num},${changeNum}) where id = ${id}`,function(err,result){
            res.send({
                data:{
                    code:200,
                    success:true
                }
            })
        })
        
    })
    
})
//删除购物车数据
router.post('/api/deleteCart',function(req,res,next){
    
    let arrId = req.body.arrId;
    
    for(let i=0;i<arrId.length;i++){
        connection.query(`delete from goods_cart where id = ${arrId[i]}`,function(error,results){
            res.send({
                data:{
                    code:200,
                    success:true,
                    msg:'删除成功'
                }
            })
        })
    }
})


//查询购物车数据
router.post('/api/selectCart',function(req,res,next){  //记得打开数据库
	//if(req.headers.token != null){
	//带上token
    let token = req.headers.token;
    let tokenObj = jwt.decode(token);//jwt解析token 
	//console.log(token);
	//console.log("token");
	//console.log( typeof token);//string
	//if(token =! string(null)){  这段和这段if(token =!null){ 是不行的//不知道// 这个行if(token ==!null)
	//if(!(token==null)){0.
	//查询用户
	connection.query(`select * from user where tel =${tokenObj.tel}`, function(error,results){
		if(results[0].id != null){
		let uId=results[0].id;//用户ID 根据用户id查
		//查询购物车  //es6语法 "" ''  和 ` 是不一样的！！！！
		connection.query(`select * from goods_cart where uId=${uId}`,function(err,result){
			res.send({
				data:{
					code:200,
					success:true,
					data:result,
				}
			})
		});
	}else{			
		res.send({
		data:{
			code:200,
			success:true,
			data:results,//注释
		}
	})}}
	);//}
	//尝试无登录也访问购物车
	/* }else{
		res.send({
			data:{
				code:200,
				success:false,
				//data:result,
				data:"",
			}
		})
	} */
});

//添加购物车数据
router.post('/api/addCart',function(req,res,next){
    //后端接收前端的参数
	let goodsId=req.body.goodsId;
	//token  
    let token = req.headers.token;
    let tokenObj = jwt.decode(token);//jwt解析token 返回对象 //不懂
    /*//console.log(tel);//{ tel: '13415726148', iat: 1647879962 }iat是过期时间*/
/*     res.send({ //第一步
        data:{a:1}
    }) */

	//如果执行就证明token过期了
	if(getTimeToken(tokenObj.exp)){
		res.send({
			data:{
			code:1000
			}
		})
	}

	//查询用户
	connection.query(`select * from user where tel = ${tokenObj.tel}`,function(error,results){
        //用户id
        let uId = results[0].id;
        //查询商品
        connection.query(`select * from goods_list where id=${goodsId}`,function(err,result){
            let goodsName = result[0].name;
            let goodsPrice = result[0].price;
            let goodsImgUrl = result[0].imgUrl;
            //查询当前用户在之前是否添加过本商品
            connection.query(`select * from goods_cart where uId=${uId} and goods_id=${goodsId}`,function(e,r){
                //用户之前是添加过商品到购物车
                if( r.length > 0 ){
                    let num = r[0].goods_num;//原来的数量
                    connection.query(`update goods_cart set goods_num = replace(goods_num,${num},${parseInt(num) + 1}) where id = ${r[0].id}`,function(e,datas){
                        res.send({
                            data:{
                                code:200,
                                success:true,
                                msg:'商品数据更新成功'
                            }
                        })
                    })
                }else{
                    //没有
                    connection.query(`insert into goods_cart (uId,goods_id,goods_name,goods_price,goods_num,goods_imgUrl) values ("${uId}","${goodsId}","${goodsName}","${goodsPrice}","1","${goodsImgUrl}")`,function(){
                       res.send({
                           data:{
                               code:200,
                               success:true,
                               msg:'商品添加成功'
                           }
                       }) 
                    })
                }
            })
        })
    })
	/*  原先的代码  造成下面的逻辑混乱  数据库不能直接添加
	connection.query(`select * from user where tel =${tokenObj.tel}`, function(error,results){
		//console.log(results[0]);
		let uId=results[0].id;//用户ID
		//查询商品  es6标点符号` " ' 弄懂
        //查询购物车
        connection.query(`select * from goods_list where id=${goodsId}`,function(err,result){
			//console.log(results[0]);
			let goodsName=result[0].name; //=results[0].name; 这里是=result[0].name; 打错了就继承上面的results的东西了
			let goodsPrice=result[0].price;
			let goodsImgUrl=result[0].imgUrl;



            connection.query(`insert into goods_cart (uId,goods_id,goods_name,goods_price,goods_num,goods_imgUrl) values ("${uId}","${goodsId}","${goodsName}","${goodsPrice}","1","${goodsImgUrl}")`,function(e,r){
				res.send({
					data:{
						code:200,
						success:true,
						msg:'添加成功'
					}
				}) 
			 })
		 })
	 })*/
 })
//修改密码
router.post('/api/recovery',function(req,res,next){
	let params = {
		userTel : req.body.phone,
		userPwd : req.body.pwd
	}
	//查询用户是否存在
	connection.query( user.queryUserTel( params ) ,function(error,results){
		//某一条记录数id
		//console.log(results);
		let id = results[0].id;//查询到的下标【0】
		let pwd = results[0].pwd;
		//'${params.userPwd}' 这里出现了个问题，这里没有引号，所以插入不成功，且不会报错
		//console.log(  `update user set pwd = replace(pwd,${pwd},${params.userPwd}) where id = ${id}` )
		connection.query(`update user set pwd = replace(pwd,'${pwd}','${params.userPwd}') where id = ${id}`,function(err,result){
			res.send({//这里send在前端的console里展示
				code:200,
				data:{
					success:true,
					msg:'修改成功'
				}
			})
		})
	})
	
	
})

//查询用户是否存在
router.post('/api/selectUser',function(req,res,next){
	
	let params = {
		userTel : req.body.phone
	}
	//查询用户是否存在
	connection.query( user.queryUserTel( params ) ,function(error,results){
		console.log(res);
		if( results.length > 0 ){
			res.send({
				code:200,
				data:{
					success:true
				}
			})
		}else{
			res.send({
				code:0,
				data:{
					success:false,
					msg:'此用户不存在'
				}
			})
		}
	})
	
})

//注册
router.post('/api/register',function(req,res,next){
	let params = {
		userTel : req.body.phone,
		userPwd : req.body.pwd,
	}
	//查询用户是否存在  //这里有问题
	connection.query( user.queryUserTel( params ) ,function(error,results){
		if(error) throw error;//！！！！！！if(error) throw error; 抛出错误就无法下一步？？ 这里没错
		//用户存在
		if( results.length > 0 ){
			res.send({
				code:200,
				data:{
					success:true,
					msg:'验证用户成功,登录成功',
					data:results[0]
				}
			})
		}else{
			//不存在，新增一条数据
			connection.query( user.inserData ( params ),function(err,result){
				connection.query( user.queryUserTel( params ) , function(e,r){
					res.send({
						code:200,
						data:{
							success:true,
							msg:'已成功注册,并登录成功',
							data:r[0]
						}
					})
				})
			})
		}
	})
	
})


//增加一个用户
router.post("/api/addUser",function(req,res,next){
	//params 参数 这个可以改 约定俗成 改为其他
	let params={
		userTel:req.body. phone
	}
	//第一步！！！
	//查询用户是否存在//了解！！抛出错误和其他的区别// 要写大于0，不写的话即使是错误的话也会返回一个result的空对象
	//一定要抛出错误 这里一定会出现错误的情况如 查到手机号了
	//下面这段函数一下子使用了sql.js和userSql.js
	connection.query( user.queryUserTel( params ) ,function(error,results){
		if(error) throw error;//抛出异常
		//用户存在
		if( results.length > 0 ){
			res.send({
				code:200,
				data:{
					success:true,
					msg:'已成功验证手机号,使用手机号登录成功',
					data:results[0]
				}
			})
		}else{//已成功注册新用户,并自动登录成功',
			//不存在，新增一条数据
			connection.query( user.inserData ( params ),function(err,result){
				connection.query( user.queryUserTel( params ) , function(e,r){
					res.send({
						code:200,
						data:{
							success:true,
							msg:'已成功注册新用户,并自动登录成功',
							data:r[0]
						}
					})
				})
			})
		}
	})
});

//npm install qcloudsms_js 在里面应该有请求的地址 配置好的环境
//十六、接入短信验证码 SDK api链接：https://github.com/qcloudsms///qcloudsms_js 16.1 下载 npm install qcloudsms_js 安装包
//发送短信验证码
router.post("/api/code",function(req,res,next){
	let tel = req.body.phone;
	
	// 短信应用SDK AppID
	var appid = 不告诉你;  // SDK AppID是1400开头
	
	// 短信应用SDK AppKey
	var appkey = "不告诉你";
	
	// 需要发送短信的手机号码
	var phoneNumbers = [tel];
	
	// 短信模板ID，需要在短信应用中申请
	var templateId = 不告诉你;  // NOTE: 这里的模板ID`7839`只是一个示例，真实的模板ID需要在短信控制台中申请
	
	// 签名
	var smsSign = "V6T";  // NOTE: 这里的签名只是示例，请使用真实的已申请的签名, 签名参数使用的是`签名内容`，而不是`签名ID`
	
	// 实例化QcloudSms
	var qcloudsms = QcloudSms(appid, appkey);
	
	// 设置请求回调处理, 这里只是演示，用户需要自定义相应处理回调
	//有名字上的冲突 function callback(err, res, resData) {  要改名字ress
	function callback(err, ress, resData) {
	    if (err) {
	        console.log("err: ", err);
	    } else {        
			//后端显示无所谓
			console.log("request data: ", ress.req);
        	console.log("response data: ", resData);
			//注意这个res就还是res  是下面的才需要改为ress
			//res.send({ 一定要写，给前端返回，返回失败就前端空等了
			//失败 两个原因 第一个 网 后端无法给服务器送信息。二后端返回数据的无法传回前端
			res.send({
				code:200,//code200成功
				data:{
					success:true,
					data:ress.req.body.params[0]//这个就是短信的验证码，然后要做的是和前端比较//比较正规的网站会对这个做加密
				}
			})
	    }
	}
	/* 
	POST /api/code 200 187.584 ms - 48
	err:  Error: getaddrinfo ENOTFOUND yun.tim.qq.com
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'yun.tim.qq.com'
  无网后台就会反映这个无法链接 'yun.tim.qq.com'主机，进行通信
  */
	var ssender = qcloudsms.SmsSingleSender();
	//这个变量：params 就是往手机上，发送的短信
	var params = [  Math.floor( Math.random()*(9999-1000))+1000   ];//这里做一个生产四位数随机数
	ssender.sendWithParam(+86, phoneNumbers[0], templateId,//国内电话号码86
	  params, smsSign, "", "", callback);  // 签名参数不能为空串
})

//用post来做
router.post('/api/login',function(req,res,next){
//后端要接收前端传递过来的值  前端传来的值在.$axios里面
let params = {
	userTel : req.body.userTel,
	userPwd : req.body.userPwd
};

//每次登陆后都更新token
let userTel = params.userTel;
let userPwd = params.userPwd  || '666666';
//引入token包
let jwt = require('jsonwebtoken');
//用户信息

let payload = {tel:userTel};
//口令
let secret = 'xiaoluxian';
//生成token
//let token = jwt.sign(payload,secret);这个是没有设置过期时间的
//下面设置过期时间
let token = jwt.sign(payload,secret,{
	expiresIn:600000//秒  60  '1h'
});

//接收完后去下面赋值查询
//user 就是上面var的方法？变量?
//查询用户手机号是否存在//function记录树
connection.query( user.queryUserTel(params) ,function(error,results){
	//手机号存在 > 0  //长度大于0
	if( results.length > 0 ){
		//记录的id
		let id=results[0].id;

		//再去查询手机号  //queryUserPwd  userSql里面的方法  result是返回的  再次查询
		connection.query( user.queryUserPwd( params ) ,function(err,result){//抛出err
			/*console.log(result.length);
			console.log("---------------");
			console.log(result[0]);
			console.log("---------------");
			console.log(result); */
			if(  result.length > 0 ){
				//更新新token tokn vchar类型要加''
				connection.query(`update user set token= '${token}' where id =${id}`,function(){
				//手机号和密码都对
				res.send({
					code:200,
					data:{
						success:true,//成功
						msg:'登录成功',//在UserLogin里面有msg的定义//好像不是这个原因 msg为了方便而已				
						data:result[0]//返回result【0】//全部 包括名字//登录账号/登陆密码
					}
				})
				})

			}else{
				//密码不对
				res.send({
					code:302,
					data:{
						success:false,//失败
						msg:'密码不正确'
					}
				})
			}
		})
		
	}else{
		//不存在
		res.send({
			code:301,
			data:{
				success:false,//失败
				msg:'手机号不存在'
			}
		})
	}
})
})

//查询商品id的数据
router.get('/api/goods/id',function(req,res,next){
	let id = req.query.id;
	/* console.log(id); */
	connection.query('select * from goods_list where id='+id+'',function(error,results){
		if( error ) throw error;
		res.json({
			code:0,
			data:results[0]
		})
	})
})
//分类的接口
router.get('/api/goods/list',function(req,res,next){
	
	res.send({
		code:0,
		data:[
			{
				//一级
				id:0,
				name:'端游',
				data:[
					{
						//二级
						id:0,
						name:'端游',
						list:[
						//三级
							{
								id:0,
								name:'穿越火线',
								imgUrl:'./images/CF1.jpeg'
							},
							{
								id:1,
								name:'刀塔1',
								imgUrl:'./images/DOTA11.jpeg'
							},
							{
								id:3,
								name:'刀塔2',
								imgUrl:'./images/DOTA21.jpeg'
							},
							{
								id:4,
								name:'刀塔3',
								imgUrl:'./images/DOTA3.jpeg'
							},
							{
								id:5,
								name:'CSGO',
								imgUrl:'./images/CSGO11.jpeg'
							},
							{
								id:6,
								name:'战舰世界',
								imgUrl:'./images/zjsj.jpeg'
							}
						]
					}
				]
			},
			{
				//一级
				id:1,
				name:'手游',
				data:[
					{
						//二级
						id:0,
						name:'手游',
						list:[
						//三级
							{
								id:0,
								name:'王者荣耀',
								imgUrl:'./images/wzry1.jpeg'
							},
							{
								id:1,
								name:'原神',
								imgUrl:'./images/ys1.jpeg'
							},
							{
								id:3,
								name:'穿越火线/安卓',
								imgUrl:'./images/CF2.jpeg'
							},
							{
								id:4,
								name:'穿越火线/苹果',
								imgUrl:'./images/CF3.jpeg'
							},
							{
								id:5,
								name:'QQ飞车',
								imgUrl:'./images/fc3.jpeg'
							},
							{
								id:6,
								name:'阴阳师',
								imgUrl:'./images/yys.jpeg'
							}
						]
					}
				]
			},
			{
				//一级
				id:2,
				name:'页游',
				data:[
					{
						//二级
						id:0,
						name:'页游',
						list:[
						//三级
							{
								id:0,
								name:'贪玩蓝月',
								imgUrl:'./images/twly.jpeg'
							},
							{
								id:1,
								name:'三国杀',
								imgUrl:'./images/sgs.jpeg'
							},
							{
								id:3,
								name:'神武3',
								imgUrl:'./images/sw1.jpeg'
							},
							{
								id:4,
								name:'神武2',
								imgUrl:'./images/sw2.jpeg'
							},
							{
								id:5,
								name:'传奇霸业',
								imgUrl:'./images/cqby.jpeg'
							},
							{
								id:6,
								name:'笑傲江湖',
								imgUrl:'./images/xajh.jpeg'
							}
						]
					}
				]
			},
			{
				//一级
				id:3,
				name:'游戏周边',
				data:[
					{
						//二级
						id:0,
						name:'游戏周边',
						list:[
						//三级
							{
								id:0,
								name:'散热背甲',
								imgUrl:'./images/srbj.jpeg'
							},
							{
								id:1,
								name:'充电器',
								imgUrl:'./images/cdq.jpeg'
							},
							{
								id:3,
								name:'游戏数据线',
								imgUrl:'./images/cdx.jpeg'
							},
							{
								id:4,
								name:'鼠标垫',
								imgUrl:'./images/sbd.jpeg'
							},
							{
								id:5,
								name:'键盘',
								imgUrl:'./images/jp.jpeg'
							},
							{
								id:6,
								name:'充电宝',
								imgUrl:'./images/cdb.jpeg'
							}
						]
					}
				]
			},
			{
				//一级
				id:4,
				name:'游戏动漫',
				data:[
					{
						//二级
						id:0,
						name:'游戏动漫',
						list:[
						//三级
							{
								id:0,
								name:'头文字D',
								imgUrl:'./images/twzd.jpeg'
							},
							{
								id:1,
								name:'湾岸MigNight',
								imgUrl:'./images/MigNight.jpeg'
							},
							{
								id:3,
								name:'名侦探柯南',
								imgUrl:'./images/mztkn.jpeg'
							},
							{
								id:4,
								name:'海贼王',
								imgUrl:'./images/hzw.jpeg'
							},
							{
								id:5,
								name:'少年歌行',
								imgUrl:'./images/sngx.jpeg'
							},
							{
								id:5,
								name:'JOJO的奇妙冒险',
								imgUrl:'./images/JOJO.jpeg'
							}
						]
					}
				]
			},
			{
				//一级
				id:5,
				name:'游戏点卡',
				data:[
					{
						//二级
						id:0,
						name:'游戏点卡',
						list:[
						//三级
							{
								id:0,
								name:'腾讯Q币',
								imgUrl:'./images/QB.jpeg'
							},
							{
								id:1,
								name:'盛大',
								imgUrl:'./images/shengda.jpeg'
							},
							{
								id:3,
								name:'巨人网络',
								imgUrl:'./images/jrww.jpeg'
							},
							{
								id:4,
								name:'网易游戏',
								imgUrl:'./images/wyyx.jpeg'
							},
							{
								id:5,
								name:'完美世界',
								imgUrl:'./images/wmsj.jpeg'
							},
							{
								id:6,
								name:'纵游一点通',
								imgUrl:'./images/zyydt.jpeg'
							},
						]
					}
				]
			},
			
		]
	})
		
})

/* 写一个接口使用 connection 的数据 */

router.get('/api/goods/shopList',function(req,res,next){
	//前端给后端的数据
	let [searchName,orderName] = Object.keys(req.query);
	let [name,order] = Object.values(req.query);

	connection.query('select * from goods_list where name like "%'+name+'%" order by '+orderName+' '+order+'',function(error,results){
		res.send({
			code:0,
			data:results
		})
	})
	
})

//查询商品数据接口
//有问题，已经废弃
//router.get("/api/goods/shopList",function(req,res,next){
  /* console.log(req.query.searchName);*//* 这里是在后端中console输出 */
  /* let searchName =req.query.searchName; *//* 前端给后端的数据 */
  //let [searchName,orderName] = Object.keys(req.query);//{a：1}  前面拿a 后面拿b
 // let [name,order] = Object.values(req.query);/*出现下面的原因是.写成,了  （状态码：500） */
  //console.log(searchName,orderName,name,order);//在后端显示  调试用
/* xhr.js?1a5c:210 
  GET http://localhost:8080/api/goods/shopList?searchName=%E7%9A%84&undefined=desc 500 (Internal Server Error)
    GET /api/goods/shopList?searchName=%E7%9A%84&undefined=desc 500 2.138 ms - 1189
  */
  //connection.query('SELECT * FROM goods_list where name like "%'+searchName+'%"',function(error,results){
  //  /* 直接返回数据 *///res.send({code:0,data:results})
  //});
  //修改后  可以修改（某些置顶）
  //let zh='select * from goods_list where name like "%'+name+'%"';/* 普通的推广 */
  //let pricenum='select * from goods_list where name like "%'+name+'%" order by '+orderName+' '+order+'';/* 大小排列 */
  /* 推广 *///let extension='select * from goods_list where name like "%'+name+'%" order by '+orderName+'desc';//需要设立综合的《zh》的数字大小
  //let transmitSql;
  //if(orderName==("price"||"num")){/* 这里括号不括号都一样 */
  //    transmitSql=zh;
  //    /*  transmitSql=extension; */
  //}
  //else{
  //  transmitSql=pricenum;
  //}
  //console.log(transmitSql);  /* 输出sql语句查错 */
  //connection.query(transmitSql,function(error,results){
	//	res.send({
	//		code:0,
	//		data:results
	//	})
  //	}) 
  //});

/*
需要跟HomeView里面的url保持一致  
created() {
    axios({ url: "/api/home" }).then((res) => {
      console(res);
    });
  }, 
  */
 /* req（目的地） res（出发地）  next（默认放过）*/
 /* Api接口 /api/home/index_list/0/data */
 /* 注意一个弱智的问题，就是请求了好久，发现请求后台出错，结果发现是后台关闭了 */

 //首页大红袍的数据
 //xhr.js?1a5c:210      
 //GET http://localhost:8080/api/home/index_list/1/data/1 404 (Not Found)
 //注意这里使用的是get方法
 /* router.get('/api/index_list/1/data/1', function(req, res, next) {
  res.send({
    code:0,
    data:[
      {
        id:1,
        type:'adList',
        data:[
          {
          id:1,
          imgUrl:'./image/dhp.jepg',
        }, 
        {
          id:2,
          type:'likeList',
          data:[
            {
              id: 1,
              imgUrl: "./images/like.jpeg",
              name: "游戏",
              price: 299,
            },
            {
              id: 2,
              imgUrl: "./images/like.jpeg",
              name: "游戏",
              price: 299,
            },
            {
              id: 3,
              imgUrl: "./images/like.jpeg",
              name: "游戏",
              price: 299,
            },
            {
              id: 4,
              imgUrl: "./images/like.jpeg",
              name: "游戏",
              price: 299,
            },
          ]
        }, 
      ]
      },
      
    ]
  })
 }, */


//第八个 装修中
router.get('/api/index_list/7/data/1', function(req, res, next) {
	res.send({/* res.json也行 */
		code:0,/* code为0 代表的是？ */ 
		data:[
			{
				id:0,
				type:'adList',
				data:[
					{
						id:1,
						imgUrl:'./images/fc3.jpeg'
					},
					{
						id:2,
						imgUrl:'./images/wpzz.jpeg'
					}
				]
			},						
		]
	})
})

//第七个 装修中
router.get('/api/index_list/6/data/1', function(req, res, next) {
	res.send({/* res.json也行 */
		code:0,/* code为0 代表的是？ */ 
		data:[
			{
				id:0,
				type:'adList',
				data:[
					{
						id:1,
						imgUrl:'./images/fc2.jpeg'
					},
					{
						id:2,
						imgUrl:'./images/sg2.jpeg'
					}
				]
			},						
		]
	})
})

//第六个 装修中
router.get('/api/index_list/5/data/1', function(req, res, next) {
	res.send({/* res.json也行 */
		code:0,/* code为0 代表的是？ */ 
		data:[
			{
				id:0,
				type:'adList',
				data:[
					{
						id:1,
						imgUrl:'./images/fc1.jpeg'
					},
					{
						id:2,
						imgUrl:'./images/sg1.jpeg'
					}
				]
			},						
		]
	})
})

//第五个 手游
router.get('/api/index_list/4/data/1', function(req, res, next) {
	res.send({/* res.json也行 */
		code:0,/* code为0 代表的是？ */ 
		data:[
			{
				id:0,
				type:'adList',
				data:[
					{
						id:1,
						imgUrl:'./images/sy1.jpeg'
					},
					{
						id:2,
						imgUrl:'./images/sy2.jpeg'
					},
					{
						id:3,
						imgUrl:'./images/sy3.jpeg'
					}
				]
			},						
		]
	})
})

 //第四个 页游
 router.get('/api/index_list/3/data/1', function(req, res, next) {
	res.send({/* res.json也行 */
		code:0,/* code为0 代表的是？ */ 
		data:[
			{
				id:0,
				type:'adList',
				data:[
					{
						id:1,
						imgUrl:'./images/yy1.jpeg'
					},
					{
						id:2,
						imgUrl:'./images/yy2.jpeg'
					}
				]
			},						
		]
	})
})
//第三个 端游
 router.get('/api/index_list/2/data/1', function(req, res, next) {
	res.send({/* res.json也行 */
		code:0,/* code为0 代表的是？ */ 
		data:[
			{
				id:0,
				type:'adList',
				data:[
					{
						id:1,
						imgUrl:'./images/dy1.jpeg'
					},
					{
						id:2,
						imgUrl:'./images/dy2.jpeg'
					}
				]
			},						
		]
	})
})
 //第二个，推荐&资讯
 router.get('/api/index_list/1/data/1', function(req, res, next) {
	res.send({/* res.json也行 */
		code:0,/* code为0 代表的是？ */ 
		data:[
			{
				id:0,
				type:'adList',
				data:[
					{
						id:1,
						imgUrl:'./images/news1.jpeg'
					},
					{
						id:2,
						imgUrl:'./images/news2.jpeg'
					}
				]
			},
			{
				id:1,
				type:'likeList',
				data:[
					{
						id:1,
						imgUrl:'./images/simple.jpeg',
						name:'CSGO-simple-海报',
						price:299
					},
					{
						id:2,
						imgUrl:'./images/niko.jpeg',
						name:'CSGO-Niko-海报',
						price:299
					},
					{
						id:3,
						imgUrl:'./images/cz.jpeg',
						name:'二环十三郎-陈震-海报',
						price:299
					},
					{
						id:4,
						imgUrl:'./images/pdd.jpeg',
						name:'刘谋PDD-海报',
						price:299
					},
					{
						id:5,
						//null
					},
					{
						id:6,
					},
				]
			}
			
		]
	})
})

/*
 //首页推荐的数据   不知道哪里出错了
router.get('/api/index_list/0/data/1', function(req, res, next) {  //home ？？
  res.send({
    code:0,/* 代表请求成功 
    /*data:{ 这里是{}不是[]，即使写错了，后端编译也不会发生错误，但是会影响功能实现 {}，如果写成[]就是数组了
    data:{
        /*topBar = : >? 
		topBar:[
			{id:0,label:'首页'},
			{id:1,label:'推荐&资讯'},
			{id:2,label:'端游'},
			{id:3,label:'页游'},
			{id:4,label:'手游'},
			{id:5,label:'装修中'},
			{id:6,label:'装修中'},
			{id:7,label:'装修中'},
		],
        data :[  //二层了 data.data
              //这是swiper  第一
          {
            id:0,
            type:'swiperList',
            data:[
              {id:0,imgUrl:'./images/swiper1.jpeg'},
              {id:1,imgUrl:'./images/swiper2.jpeg'},
              {id:3,imgUrl:'./images/swiper3.jpeg'},
            ]
          },
        //这是icons  第二
        {
        id:1,
        type:'iconsList',
          data:[
          {
            id: 1,
            title: "1" ,
            imgUrl: "./images/icons1.png",
          },
          {
            id: 2,
            title: "2" ,
            imgUrl: "./images/icons2.png",
          },
          {
            id: 3,
            title: "3" ,
            imgUrl: "./images/icons3.png",
          },
          {
            id: 4,
            title: "4" ,
            imgUrl: "./images/icons4.png",
          },
          {
            id: 5,
            title: "5" ,
            imgUrl: "./images/icons5.png",
          },
          ]
        },
        //构建爆款推荐 第三
        {
          id:3,
          type:'recommendList',
          data:[
			{
				id: 1,
				name: "名字3",
				content: "内容222",
				price: "价格3333",
				imgUrl: "./images/recommend.jpeg",
			},
          {
          id: 2,
          name: "名字2",
          content: "内容222",
          price: "价格3333",
          imgUrl: "./images/recommend.jpeg",
          },
          {},
          {},
		]
        },
            //猜你喜欢 第四
          {
          id:4,
          type:'likeList',
          data:[
          {
            id:1,
            imgUrl:'./images/like.jpeg',
            name:"12件套",
            price:238
          },        
          {
            id:2,
            imgUrl:'./images/like.jpeg',
            name:"12件套",
            price:125
          },
          {
            id:3,
            imgUrl:'./images/like.jpeg',
            name:"12件套",
            price:650
          },
		  {
            id:3,
            imgUrl:'./images/like.jpeg',
            name:"12件套",
            price:120				
          },
          ] 
          },
        ]},    
}) 
})*/
/* 后端改动后需要进行重启 npm start */
router.get('/api/index_list/0/data/1', function(req, res, next) {
	res.send({
		code:0,
		data:{
			topBar:[
				{id:0,label:'推荐'},
				{id:1,label:'推荐&资讯'},
				{id:2,label:'端游'},
				{id:3,label:'页游'},
				{id:4,label:'手游'},
				{id:5,label:'装修区'},
				{id:6,label:'装修区'},
				{id:7,label:'装修区'},
			],
			data:[
				//这是swiper
				{
					id:0,
					type:'swiperList',
					data:[
						{id:0,imgUrl:'./images/swiper1.jpeg'},
						{id:1,imgUrl:'./images/swiper2.jpeg'},
						{id:3,imgUrl:'./images/swiper3.jpeg'}
					]
				},
				//这是icons
				{
					id:1,
					type:'iconsList',
					data:[
						{
							id:1,
							title:'放松吹水',
							imgUrl:'./images/icons1.png'
						},
						{
							id:2,
							title:'交流人生',
							imgUrl:'./images/icons2.png'
						},
						{
							id:3,
							title:'送礼',
							imgUrl:'./images/icons3.png'
						},
						{
							id:4,
							title:'领游戏福利',
							imgUrl:'./images/icons4.png'
						},
						{
							id:5,
							title:'兑换验证码',
							imgUrl:'./images/icons5.png'
						}
					]
				},
				//爆款推荐
				{
				id:2,
				type:'recommendList',
				data:[
				{
					id: 1,
					name: "大多数-Nobody",
					content: "第一人称-模拟生存游戏",
					price: "58",
					imgUrl: "./images/dds.jpeg",
				  },
				  {
					id: 2,
					name: "CSGO",
					content: "反恐精英:全球攻势 S1酣战时",
					price: "98",
					imgUrl: "./images/CSGO.jpeg",
				  },
				  {
					id: 3,
					name: "DOTA2",
					content: "DOTA电竞-畅享公平竞技体验",
					price: "78",
					imgUrl: "./images/DOTA2.jpeg",
				  },
				]
				},
				/* {
					id:2,
					type:'recommendList',
					data:[
						{
							id:1,
							name:'龙井1號铁罐250g',
							content:'鲜爽甘醇 口粮首选',
							price:'68',
							imgUrl:'./images/recommend.jpeg'
						},
						{
							id:2,
							name:'龙井1號铁罐250g',
							content:'鲜爽甘醇 口粮首选',
							price:'68',
							imgUrl:'./images/recommend.jpeg'
						}
					]
				}, */
				//猜你喜欢
				{
					id:3,
					type:'likeList',
					data:[
						{
							id:1,
							imgUrl:'./images/wzry1.jpeg',
							name:'王者荣耀 不是一个人的王者，而是团队的荣耀！',
							price:100
						},
						{
							id:2,
							imgUrl:'./images/ys1.jpeg',
							name:'原神 米哈游自研的一款全新开放世界冒险RPG',
							price:105
						},
						{
							id:3,
							imgUrl:'./images/DOTA21.jpeg',
							name:'DOTA2 全球经典电竞大作DOTA2，进入刀塔畅享公平竞技体验。',
							price:108
						},
						{
							id:4,
							imgUrl:'./images/DOTA11.jpeg',
							name:'DOTA1 初代经典游戏',
							price:98
						},
						{
							id:5,
							imgUrl:'./images/DOTA3.jpeg',
							name:'DOTA3 全新版本-畅快游戏',
							price:118
						},
						{
							id:6,
							imgUrl:'./images/zjsj.jpeg',
							name:'战舰世界',
							price:108
						},
						{
							id:7,
							imgUrl:'./images/CF1.jpeg',
							name:'穿越火线 三亿鼠标的枪战梦想',
							price:69
						},
						{
							id:8,
							imgUrl:'./images/CF2.jpeg',
							name:'穿越火线 安卓畅玩',
							price:49
						},
						{
							id:9,
							imgUrl:'./images/CF3.jpeg',
							name:'穿越火线 IOS/苹果-FIRE',
							price:39
						},
						{
							id:10,
							imgUrl:'./images/CF4.jpeg',
							name:'CFHD-高端穿越火线',
							price:79
						}
					]
				}
				
			]
		}
	})
});

/* 在我们自己写模块的时候，需要在模块最后写好模块接口，声明这个模块对外暴露什么内容，module.exports 提供了暴露接口的方法。 */
/* export default router; */
/* module.exports = router;*/

module.exports = router; 
/* export default router; */

/* C:\Users\39007\Desktop\vue-gameshop\server\node_modules\express\lib\router\index.js:458
      throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
出现问题的原因非常弱智  应该是{}()没有对上
      */